﻿using System;

namespace Library.OrmEnterpriseEntity.TableInfo {
	///<summary>
	///</summary>
	public class Int32Column : Column<Int32>, IConvertible {
		///<summary>
		///</summary>
		///<param name="metadata"></param>
		///<param name="table"></param>
		public Int32Column(DbColumnView metadata, DbTable table)
			: base(metadata, table) {
		}
		public override string ToString(string format, IFormatProvider formatProvider) {
			return Value.ToString(format, formatProvider);
		}
		///<summary>
		///</summary>
		///<param name="value"></param>
		///<returns></returns>
		public static implicit operator Int32Column(int value) {
			return new Int32Column(Int32ColumnView.Null, DbTable.Null) { Value = value };
		}
		///<summary>
		///</summary>
		public const Int32 DefaultInt32 = 0;
		internal static readonly Type Int32ColumnType = typeof(Int32Column);


		protected override int Default {
			get { return DefaultInt32; }
		}



		//public override DbType DbType {
		//  get { return DbType.Int32; }
		//}

		protected override int ConvertFrom(object value) {
			return Convert.ToInt32(value);
		}

		protected override bool Equal(int t1, int t2) {
			return t1 == t2;
		}

		internal override bool ValueNotDefault {
			get { return Value != 0; }
		}

		#region Implementation of IConvertible

		TypeCode IConvertible.GetTypeCode() {
			return ((IConvertible)Value).GetTypeCode();
		}

		bool IConvertible.ToBoolean(IFormatProvider provider) {
			return ((IConvertible)Value).ToBoolean(provider);
		}

		char IConvertible.ToChar(IFormatProvider provider) {
			return ((IConvertible)Value).ToChar(provider);
		}

		sbyte IConvertible.ToSByte(IFormatProvider provider) {
			return ((IConvertible)Value).ToSByte(provider);
		}

		byte IConvertible.ToByte(IFormatProvider provider) {
			return ((IConvertible)Value).ToByte(provider);
		}

		short IConvertible.ToInt16(IFormatProvider provider) {
			return ((IConvertible)Value).ToInt16(provider);
		}

		ushort IConvertible.ToUInt16(IFormatProvider provider) {
			return ((IConvertible)Value).ToUInt16(provider);
		}

		int IConvertible.ToInt32(IFormatProvider provider) {
			return ((IConvertible)Value).ToInt32(provider);
		}

		uint IConvertible.ToUInt32(IFormatProvider provider) {
			return ((IConvertible)Value).ToUInt32(provider);
		}

		long IConvertible.ToInt64(IFormatProvider provider) {
			return ((IConvertible)Value).ToInt64(provider);
		}

		ulong IConvertible.ToUInt64(IFormatProvider provider) {
			return ((IConvertible)Value).ToUInt64(provider);
		}

		float IConvertible.ToSingle(IFormatProvider provider) {
			return ((IConvertible)Value).ToSingle(provider);
		}

		double IConvertible.ToDouble(IFormatProvider provider) {
			return ((IConvertible)Value).ToDouble(provider);
		}

		decimal IConvertible.ToDecimal(IFormatProvider provider) {
			return ((IConvertible)Value).ToDecimal(provider);
		}

		DateTime IConvertible.ToDateTime(IFormatProvider provider) {
			return ((IConvertible)Value).ToDateTime(provider);
		}

		string IConvertible.ToString(IFormatProvider provider) {
			return ((IConvertible)Value).ToString(provider);
		}

		object IConvertible.ToType(Type conversionType, IFormatProvider provider) {
			return ((IConvertible)Value).ToType(conversionType, provider);
		}

		#endregion
	}
}
